<template>
  <div class="base-container">
    <t-row style="align-items: stretch" :gutter="14">
      <t-col :span="12">
        <t-card class="step-card" size="small" title="年度计划">
          <t-form ref="form2" :colon="false" class="step-form"
                  labelWidth="100px">
            <t-row>
              <t-col :span="6">
                <t-form-item label="计划名称:">
                  {{ planData.planName }}
                </t-form-item>
              </t-col>
              <t-col :span="6">
                <t-form-item label="所属年度:">
                  {{ planData.planYear }}
                </t-form-item>
              </t-col>
              <t-col :span="6">
                <t-form-item labelWidth="200">
                  <template #label>
                    <p style="color:red">申报开始时间:</p>
                  </template>
                  <p style="color:red">{{ planData.startDate }}</p>
                </t-form-item>
              </t-col>
              <t-col :span="6">
                <t-form-item>
                  <template #label>
                    <p style="color:red">申报截止时间:</p>
                  </template>
                  <p style="color:red">{{ planData.endDate + '  '}}23:59:59</p>
                </t-form-item>
              </t-col>
              <t-col :span="6">
                <t-form-item label="说明:">
                  {{ planData.note }}
                </t-form-item>
              </t-col>
              <t-col :span="6">
                <t-form-item>
                  <template #label>
                    <p style="color:red">修改截止时间:</p>
                  </template>
                  <p style="color:red">{{ planData.spEndDate + '  '}}23:59:59</p>
                </t-form-item>
              </t-col>
              <t-col :span="6">
                <t-form-item label="附件:">
                  <a class="t-button-link" target="_blank" v-for="(item,index) in planData.sysAttMainEntitys"
                     :href="item.fullFilePath" :key="index">
                    {{ item.fileName }}
                  </a>
                </t-form-item>
              </t-col>
              <t-col :span="6">
                <t-form-item>
                  <template #label>
                    <p style="color:red">推荐截止时间:</p>
                  </template>
                  <p style="color:red">{{ planData.recommendEndDate + '  '}}23:59:59</p>
                </t-form-item>
              </t-col>
            </t-row>
          </t-form>
        </t-card>
      </t-col>
    </t-row>
    <t-form ref="form" labelAlign="top" :colon="true" class="step-form" :data="formData" :rules="rules"
            labelWidth="180px">
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="（一）江西省交通投资集团有限责任公司微创新成果大赛报名表">
            <t-card class="step-card" size="small" title="基本信息">
              <t-row>
                <t-col :span="6">
                  <t-form-item label="微创新成果名称" name="name">
                    <t-input clearable style="width: 390px" v-model="formData.name"></t-input>
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="应用领域" name="applicationField">
                    <t-select clearable style="width: 390px" v-model="formData.applicationField"
                              :options="dict.type.application_field">
                    </t-select>
                  </t-form-item>
                </t-col>
              </t-row>
              <t-row>
                <t-col :span="6">
                  <t-form-item label="微创新成果应用项目" name="applicationProject">
                    <t-input clearable style="width: 390px" v-model="formData.applicationProject"></t-input>
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="创新类别" name="innovationCategory">
                    <t-select clearable style="width: 390px" v-model="formData.innovationCategory"
                              :options="dict.type.innovation_category">
                    </t-select>
                  </t-form-item>
                </t-col>
              </t-row>
              <t-row>
                <t-col :span="6">
                  <t-form-item label="申报负责人" name="leaderName">
<!--                    <t-input disabled clearable style="width: 390px" v-model="formData.leaderName"></t-input>-->
                    <t-select
                      v-model="formData.leaderName"
                      creatable
                      filterable
                      @change="onLeaderNameChange"
                      placeholder="请输入姓名"
                      :loading="leaderLoading"
                      @search="remoteProjectLeaderMethod"
                      :options="projectLeaderOptions"
                      @create="createProjectLeaderOptions"
                      style="width: 390px"
                    />
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item  label="工作单位" name="deptName">
                    <t-tree-select clearable filterable style="width: 390px"
                                   :treeProps="{keys: {value: 'id'}}"
                                   @change="(val,content)=>{formData.deptName=content.node.data.label}"
                                   v-model="formData.companyId" :data="deptMenuOptions"
                                   placeholder="选择工作单位"></t-tree-select>
<!--                    <t-input  clearable style="width: 390px" v-model="formData.deptName"></t-input>-->
<!--                    <t-tree-select  @change="(val,content)=>{formData.companyId=content.node.data.id;}" v-if="formData.isInnerCompany==='1'" style="width:390px" clearable filterable-->
<!--                                   :treeProps="{keys: {value: 'label'}}" v-model="formData.deptName" :data="deptMenuOptions"-->
<!--                                   placeholder="选择单位">-->

<!--                      <template #label>-->
<!--                        <t-switch-->
<!--                          size="medium"-->
<!--                          v-model="formData.isInnerCompany"-->
<!--                          :label="['内部', '外部']"-->
<!--                          :customValue="['1', '0']"-->
<!--                          @change="()=>{formData.deptName='';formData.companyId=null;}"-->
<!--                        ></t-switch>-->
<!--                      </template>-->
<!--                    </t-tree-select>-->
<!--                    <t-select-->
<!--                      v-else-->
<!--                      v-model="formData.deptName"-->
<!--                      creatable-->
<!--                      filterable-->
<!--                      placeholder="请输入"-->
<!--                      @change="(val,content)=>{formData.companyId = content.option?.id;}"-->
<!--                      :loading="companyLoading"-->
<!--                      @search="remoteCompanyMethod"-->
<!--                      :options="companyOptions"-->
<!--                      @create="createCompanyOptions"-->
<!--                      style="width: 390px;display: inline-block"-->
<!--                    >-->
<!--                      <div slot="tips" >搜索不到请切换外部单位后手输</div>-->
<!--                      <template #label>-->
<!--                        <t-switch-->
<!--                          size="medium"-->
<!--                          v-model="formData.isInnerCompany"-->
<!--                          :label="['内部', '外部']"-->
<!--                          :customValue="['1', '0']"-->
<!--                          @change="()=>{formData.deptName='';formData.companyId=null;}"-->
<!--                        ></t-switch>-->
<!--                      </template>-->
<!--                    </t-select>-->
                  </t-form-item>
                </t-col>
              </t-row>
              <t-row>
                <t-col :span="6">
                  <t-form-item label="身份证号" name="idCard">
                    <t-input clearable style="width: 390px" v-model="formData.idCard"></t-input>
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="手机号" name="phone">
                    <t-input clearable style="width: 390px" v-model="formData.phone"></t-input>
                  </t-form-item>
                </t-col>
              </t-row>
              <t-row>
                <t-col :span="6">
                  <t-form-item label="职务" name="duty">
                    <t-input clearable style="width: 390px" v-model="formData.duty" placeholder="请输入职务"></t-input>
                    <!--                    <t-select clearable style="width: 390px" v-model="formData.duty"-->
                    <!--                              :options="dict.type.duty">-->
                    <!--                    </t-select>-->
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="邮箱" name="email">
                    <t-input clearable style="width: 390px" v-model="formData.email"></t-input>
                  </t-form-item>
                </t-col>
              </t-row>
              <t-row>
                <t-col :span="6">
                  <t-form-item label="技术职称" name="profTitId">
                    <t-tree-select clearable @change="onProfTitIdChange" filterable style="width: 390px"
                                   :treeProps="{keys: {value: 'id',label:'name'}, valueMode: 'onlyLeaf'}"
                                   v-model="formData.profTitId" :data="profTitOptions"
                                   placeholder="请选择技术职称"></t-tree-select>
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="职称级别" name="profTit">
                    <t-select disabled clearable style="width: 390px" v-model="formData.profTit"
                              :options="dict.type.prof_tit">
                    </t-select>
                  </t-form-item>
                </t-col>
              </t-row>
              <t-row>

                <t-col :span="6">
                  <t-form-item label="微信号" name="wechat">
                    <t-input clearable style="width: 390px" v-model="formData.wechat"></t-input>
                  </t-form-item>
                </t-col>
              </t-row>
            </t-card>
            <t-card class="step-card" size="small">
              <template #title>
                主要完成人及工作单位<span style="color:red">(单个成果完成人不超过10人，每位成员当年参与的项目不能超过2项)</span>
              </template>
              <t-form-item :show-error-message="false" name="innovationMembers" label="必填">
                <innovation-member v-model="formData.innovationMembers"
                                   :editOpen="true" :form-data="formData"></innovation-member>
              </t-form-item>
            </t-card>
          </t-card>
        </t-col>
      </t-row>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small">
            <template v-slot:title>
            （二）江西省交通投资集团有限责任公司微创新大赛申报成果介绍
              <span class="textTips-color-red">如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中</span>
            </template>
            <t-form-item label="成果基本情况，包括但不限于微创新成果的需求背景、基本研究过程及内容、关键技术及创新点、推广应用情况及前景、经济效益与社会效益等。不超过1500字。"
                         name="introduceContent">
                <template #label>
                  成果基本情况，包括但不限于微创新成果的需求背景、基本研究过程及内容、关键技术及创新点、推广应用情况及前景、经济效益与社会效益等。不超过1500字。<span class="textTips-color-red">（如果遇到格式问题，请先将内容复制到word中调整好，再黏贴到系统中）</span>
                </template>
              <!--              <t-textarea clearable :autosize="{minRows: 10}" :maxlength="1500"-->
              <!--                          v-model="formData.introduceContent"></t-textarea>-->
              <tiny-mce-editor :maxlength="1500" :key="1" :textLength.sync="lengthLimitObj.introduceContent"
                               v-model="formData.introduceContent"></tiny-mce-editor>
            </t-form-item>
          </t-card>
        </t-col>
      </t-row>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="相关附件">
            <t-alert style="margin-bottom: 14px" theme="info" title="提交材料内容及要求">
              <div slot="message">
                <p class="span-txt">参赛微创新成果，应按以下规定提交材料，否则将不予通过形式审查。</p>
                <!--                <p class="span-txt">（1）申报书</p>-->
                <!--                <p class="span-txt" style="margin-left: 20px">-->
                <!--                  包括微创新大赛申报书word版及加盖公章的电子扫描件，申报书表格中填写的相关内容务必与封面保持一致，申报书格式见附件。</p>-->
                <p class="span-txt">（1）微创新视频</p>
                <p class="span-txt" style="margin-left: 20px">包括视频演示文件，视频要求时长5分钟以内, 文件大小不超过1G。</p>
                <p class="span-txt">（2）微创新图片</p>
                <p class="span-txt" style="margin-left: 20px">包括微创新项目应用现场照片或效果图5-10张，JPG格式，加图片说明。</p>
                <p class="span-txt">（3）关键技术原理及流程图</p>
                <p class="span-txt" style="margin-left: 20px">包括微创新成果的关键技术原理图、工艺流程图、制度流程图等，JPG格式，加图片说明。</p>
                <p class="span-txt">（4）其他证明材料（非必须项，自愿提供）</p>
                <p class="span-txt" style="margin-left: 20px">包括应用证明、获奖证明、知识产权证明文件、技术查新报告等。</p>
              </div>
            </t-alert>
            <!--            <t-row>-->
            <!--              <t-col :span="6">-->
            <!--                <t-form-item label="申报书" name="wcxApply">-->
            <!--                  <file-upload :multiple="true" accept="application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" v-model="formData.wcxApply" placeholder="包括微创新大赛申报书word版及加盖公章的电子扫描件，申报书表格中填写的相关内容务必与封面保持一致，申报书格式见附件。" tips="">-->
            <!--                    <t-button variant="outline">-->
            <!--                      <t-icon name="cloud-upload" slot="icon"/>-->
            <!--                      上传申报书-->
            <!--                    </t-button>-->
            <!--                  </file-upload>-->
            <!--                </t-form-item>-->
            <!--              </t-col>-->
            <!--            </t-row>-->
            <t-row>
              <t-col :span="12">
                <t-form-item label="微创新视频(包括视频演示文件，视频要求时长5分钟以内, 文件大小不超过1G。)" name="wcxVideo">
                  <template #label>
                    微创新视频(<span style="color: red">包括视频演示文件，视频要求时长5分钟以内, 文件大小不超过1G。</span>)
                  </template>
                  <file-upload :durationLimit="300" v-model="formData.wcxVideo"
                               :sizeLimitRange="[0,1024*1024*1024]" :fileList="formData.wcxVideoFiles"
                               moduleKey="wcxVideo"
                               accept="video/*"
                               theme="file" tips="">
                    <t-button variant="outline">
                      <t-icon name="cloud-upload" slot="icon"/>
                      上传微创新视频
                    </t-button>
                  </file-upload>
                </t-form-item>
              </t-col>
            </t-row>
            <t-row>
              <t-col :span="12">
                <t-form-item :show-error-message="false" label="微创新图片(包括微创新项目应用现场照片或效果图5-10张，JPG格式，加图片说明。)"
                             name="innovationImages">
                  <template #label>
                    微创新图片(<span style="color: red">包括微创新项目应用现场照片或效果图5-10张，JPG格式，加图片说明。</span>)
                  </template>
                  <innovation-image ref="innovation-image" type="1" key="innovation-image"
                                    v-model="formData.innovationImages"
                                    :editOpen="true"></innovation-image>
                </t-form-item>
              </t-col>
            </t-row>
            <t-row>
              <t-col :span="12">
                <t-form-item label="关键技术原理及流程图(包括微创新成果的关键技术原理图、工艺流程图、制度流程图等，JPG格式，加图片说明。)"
                             name="innovationGjImages">
                  <template #label>
                    关键技术原理及流程图(<span style="color: red">包括微创新成果的关键技术原理图、工艺流程图、制度流程图等，JPG格式，加图片说明。</span>)
                  </template>
                  <innovation-image  ref="innovation-gj-image" type="2" key="innovation-gj-image"
                                    v-model="formData.innovationGjImages"
                                    :editOpen="true"></innovation-image>
                </t-form-item>

              </t-col>
            </t-row>
            <t-row>
              <t-col :span="12">
                <t-form-item label="其他证明材料（非必须项，自愿提供）(包括应用证明、获奖证明、知识产权证明文件、技术查新报告等。)" name="wcxOther">
                  <template #label>
                    其他证明材料（非必须项，自愿提供）(<span style="color: red">包括应用证明、获奖证明、知识产权证明文件、技术查新报告等。</span>)
                  </template>
                  <file-upload v-model="formData.wcxOther" moduleKey="wcxOther" :fileList="formData.wcxOtherFiles"
                               :multiple="true"
                               tips="">
                    <t-button variant="outline">
                      <t-icon name="cloud-upload" slot="icon"/>
                      上传其他证明材料
                    </t-button>
                  </file-upload>
                </t-form-item>
              </t-col>
            </t-row>
          </t-card>
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button theme="primary" :loading="applyLoading" @click="onSubmit(1)">{{
              applyLoading ? '提交中...' : '暂存'
            }}
          </t-button>
          <t-tooltip content="提交后不可再编辑会进入审批流程">
            <t-button :loading="applyLoading" theme="primary" @click="onSubmit(2)">
              {{ applyLoading ? '提交中...' : '提交到单位管理员' }}
            </t-button>
          </t-tooltip>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button @click="close" variant="outline">返回</t-button>
        </t-col>
      </t-row>
    </t-form>
  </div>
</template>

<script>
import InnovationMember from "../innovation/components/innovation-member.vue";
import FileUpload from "@/components/FileUpload/index.vue"
import TinyMceEditor from "@/components/TinyMceEditor/index.vue";
import InnovationImage from "../innovation/components/innovation-image.vue";

import {getFiles} from "@/api/common";

export default {
  name: "innovation-apply",
  dicts: ["application_field", "innovation_category", "duty", "prof_tit"],
  components: {
    InnovationMember,
    FileUpload,
    TinyMceEditor,
    InnovationImage
  },
  data() {
    return {
      applyLoading: false,
      leaderLoading: false,
      lengthLimitObj: {
        introduceContent: 1500
      },
      wcxImageData: [],
      wcxImageColumns: [
        {
          colKey: 'index',
          title: "序号",
          align: "center",
          width: 80
        },
        {
          colKey: "op",
          title: "图片",
          align: "center",
        },
        {
          colKey: "note",
          title: "说明",
          align: "center",
        },
      ],
      profTitOptions: [],
      formData: {
        profTitId: null,
        companyId: null,
        name: '',
        applicationField: '',
        applicationProject: '',
        innovationCategory: '',
        leaderName: '',
        profTit: '',
        duty: '',
        phone: '',
        email: '',
        wechat: '',
        deptName: '',
        approveStatus: '1',
        innovationMembers: [],
        introduceContent: '',
        idCard: '',
        wcxApply: [],
        wcxImage: [],
        wcxImageFiles: [],
        wcxVideo: [],
        wcxVideoFiles: [],
        wcxFlow: [],
        wcxFlowFiles: [],
        wcxOther: [],
        wcxOtherFiles: [],
        sysAttMainVo: {
          sysAttMainIds: []
        },
        innovationImages: [],
        innovationGjImages: [],
        isInnerCompany: '1',
      },
      taskId: null,
      rules: {
        leaderName: [
          {
            required: true,
            message: "申报负责人不能为空",
          },
        ],
        deptName: [
          {
            required: true,
            message: "工作单位不能为空",
          },
        ],
        name: [
          {
            required: true,
            message: "微创新成果名称不能为空",
          },
        ],
        profTitId: [
          {
            required: true,
            message: "技术职称不能为空",
          },
        ],
        applicationField: [
          {
            required: true,
            message: "应用领域不能为空",
          },
        ],
        applicationProject: [
          {
            required: true,
            message: "微创新成果应用项目不能为空",
          },
        ],
        innovationCategory: [
          {
            required: true,
            message: "创新类别不能为空",
          },
        ],
        duty: [
          {
            required: true,
            message: "职务不能为空",
          },
        ],
        profTit: [
          {
            required: true,
            message: "职称不能为空",
          },
        ],
        idCard: [
          {
            required: true,
            message: "身份证号不能为空",
          },
          {
            message: "身份证号不正确",
            pattern: /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/,
          },
        ],
        email: [
          {
            required: true,
            message: "邮箱不能为空",
          },
          {email: {ignore_max_length: true}, message: '请输入正确的邮箱地址'}
        ],
        wechat: [
          {
            required: true,
            message: "微信号不能为空",
          },
        ],
        phone: [
          {
            required: true,
            message: "手机号不能为空",
          },
          {
            pattern: /^(?:(?:\+|00)86)?1\d{10}$/,
            message: '请输入正确的手机号',
            type: 'error',
            trigger: 'blur'
          },
        ],
        introduceContent: [
          {
            required: true,
            message: "成果介绍不能为空",
          },
        ],
        innovationMembers: [
          {
            required: true,
            validator: (val) => val && val.length,
            message: "主要完成人及工作单位不能为空",
            type: "error",
          }
        ],
        wcxApply: [
          {required: true, validator: (val) => val && val.length, message: `附件"申报书"不能为空`, type: "error"}
        ],
        innovationImages: [
          {required: true, validator: (val) => val.length >= 5, message: `附件"微创新图片5-10张"`, type: "error"}
        ],
        innovationGjImages: [
          {required: true, validator: (val) => val.length >= 5, message: `附件"关键技术原理及流程图"不能为空`, type: "error"}
        ],
        // wcxImage: [
        //   {required: true, validator: (val) => val.length >= 5, message: `附件"微创新图片5-10张"不能为空`, type: "error"}
        // ],
        wcxVideo: [
          {required: true, validator: (val) => val && val.length, message: `附件"微创新视频"不能为空`, type: "error"}
        ],
        // wcxFlow: [
        //   {required: true, validator: (val) => val && val.length, message: `附件"关键技术原理及流程图"不能为空`, type: "error"}
        // ],
      },
      userInfo: {},
      planData: {},
      projectLeaderOptions: [],
      companyOptions: [],
      companyLoading: false,
      deptMenuOptions: []
    }
  },
  async created() {
    const taskId = this.$route.params && this.$route.params.taskId;
    if (!taskId) {
      this.$message.error("缺少成果id");
      return false;
    }
    await this.getProfTitTreeSelect();
    this.taskId = taskId;
    const innovationId = sessionStorage.getItem(`${taskId}-wcxInnovationId`);
    if (innovationId) {
      // 获取详情
      this.$api.wcx.apply.innovationGet(innovationId).then(response => {
        // 获取附件
        getFiles(innovationId).then((res) => {
          const files = {}
          res.data.forEach((item) => {
            if (!files[item.moduleKey]) {
              files[item.moduleKey] = []
            }
            files[item.moduleKey].push({
              name: item.fileName,
              url: item.fullFilePath,
              id: item.id,
              filePath: item.filePath
            })
          })
          this.formData.wcxOtherFiles = files.wcxOther;
          // this.formData.wcxImageFiles = files.wcxImage;
          this.formData.wcxVideoFiles = files.wcxVideo;
          // this.formData.wcxFlowFiles = files.wcxFlow;
          this.formData.wcxOther = files.wcxOther?.map(val => val.id);
          // this.formData.wcxImage = files.wcxImage?.map(val => val.id);
          this.formData.wcxVideo = files.wcxVideo?.map(val => val.id);
          // this.formData.wcxFlow = files.wcxFlow?.map(val => val.id);
        });
        // this.formData = response.data
        Object.assign(this.formData, response.data);

      }).catch((e) => {
        this.$message.error(e.toString());
      });
    } else {
      this.getUserInfo();
    }
    // 获取当前计划
    this.getThisYearPlan();
    this.getDeptTreeSelect();
  },
  methods: {
    getDeptTreeSelect() {
      return this.$api.system.dept.treeSelectAll().then(response => {
        this.deptMenuOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    createCompanyOptions(value) {
      this.companyOptions.push({
        label: `${value}`,
        value,
      });
    },
    remoteCompanyMethod(search) {
      this.companyLoading = true;
      this.$api.system.dept.selectAllOutDeptList({deptName: search}).then(response => {
        this.companyOptions = response.data.map(val => ({
          ...val,
          label: `${val.deptName}`,
          value: val.deptName,
        }));
        this.companyLoading = false;
      }).catch((e) => {
        this.companyLoading = false;
        this.$message.error(e.toString());
      });
    },
    createProjectLeaderOptions(value) {
      this.projectLeaderOptions.push({
        label: `${value}`,
        value,
        name: value
      });
    },
    remoteProjectLeaderMethod(search) {
      this.leaderLoading = true;
      this.$api.system.member.searchList({name: search}).then(response => {
        this.projectLeaderOptions = response.data.map(val => ({
          ...val,
          label: `${val.name}-${val.idCard}`,
          value: `${val.name}-${val.idCard}`,
        }));
        this.leaderLoading = false;
      }).catch((e) => {
        this.leaderLoading = false;
        this.$message.error(e.toString());
      });
    },
    onLeaderNameChange(val, content) {
      const index = this.projectLeaderOptions.findIndex(val => content?.option?.id === val.id)
      this.projectLeaderOptions[index].label = this.projectLeaderOptions[index].name;
      this.$set(this.projectLeaderOptions, index, this.projectLeaderOptions[index])

      this.formData.leaderName = this.projectLeaderOptions[index].name;
      this.formData.phone = this.projectLeaderOptions[index].phone;
      this.formData.deptName = this.projectLeaderOptions[index].company;
      this.formData.profTit = this.projectLeaderOptions[index].profTit;
      this.formData.companyId = this.projectLeaderOptions[index].companyId;
      this.formData.profTitId = this.projectLeaderOptions[index].profTitId;
      this.formData.duty = this.projectLeaderOptions[index].duty;
      this.formData.email = this.projectLeaderOptions[index].email;
      this.formData.wechat = this.projectLeaderOptions[index].wechat;
      this.formData.idCard = this.projectLeaderOptions[index].idCard;
      this.formData.isInnerCompany = this.projectLeaderOptions[index].isInnerCompany;
    },
    getThisYearPlan() {
      return this.$api.wcx.apply.getThisYearPlan().then(response => {
        this.planData = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getProfTitTreeSelect() {
      return this.$api.system.profTit.list().then(response => {
        // this.profTitOptions = response.data;
        this.profTitOptions = this.handleTree(response.data, "id");
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    onProfTitIdChange(val, content) {
      this.formData.profTit = content.node.data.level;
    },
    getUserInfo() {
      this.$api.system.user.getBaseInfo().then(response => {
        this.formData.leaderName = response.data.nickName;
        this.formData.phone = response.data.phonenumber;
        this.formData.deptName = response.data.dept.deptName;
        this.formData.profTit = response.data.profTit;
        this.formData.profTitId = response.data.profTitId;
        this.formData.duty = response.data.duty;
        this.formData.email = response.data.email;
        this.formData.wechat = response.data.wechat;
        this.formData.idCard = response.data.idCard;
        this.formData.companyId = response.data.departmentId;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    onSubmit(type) {
      if (type === 1) {
        this.$refs.form.validate({
          fields: ['name']
        }).then((validateResult) => {
          if (validateResult === true) {
            this.applyLoading = true;
            if (!this.formData.id) {
              this.$api.wcx.apply.innovationAdd({
                ...this.formData,
                // innovationStatus: "1",
                sysAttMainVo: {
                  sysAttMainIds: [].concat(this.formData.wcxVideo || [], this.formData.wcxFlow || [], this.formData.wcxImage || [], this.formData.wcxOther || [])
                }
              }).then(response => {
                sessionStorage.setItem(`${this.taskId}-wcxInnovationId`, response.data.id)
                this.formData.id = response.data.id;
                this.applyLoading = false;
                this.$message.success('暂存成功');
                this.close();
              }).catch((e) => {
                this.applyLoading = false;
                this.$message.error(e.toString());
              });
            } else {
              this.$api.wcx.apply.innovationUpdate({
                ...this.formData,
                // innovationStatus: "1",
                sysAttMainVo: {
                  sysAttMainIds: [].concat(this.formData.wcxVideo || [], this.formData.wcxFlow || [], this.formData.wcxImage || [], this.formData.wcxOther || [])
                }
              }).then(response => {
                this.applyLoading = false;
                this.$message.success('暂存成功');
                this.close();
              }).catch((e) => {
                this.applyLoading = false;
                this.$message.error(e.toString());
              });
            }
          } else {
            const firstError = Object.values(validateResult)[0]?.[0]?.message;
            this.$message.error(firstError);
          }
        })

      } else {
        this.$refs.form.validate().then((validateResult) => {
          if (validateResult === true) {
            if (this.lengthLimitObj.introduceContent > this.maxlength) {
              this.$message.error(`成果基本情况 当前字数${this.lengthLimitObj.introduceContent}，限制字数${this.maxlength}`)
              return false;
            }
            const isValidate = this.$refs["innovation-image"].checkData()
            if (!isValidate) {
              return false;
            }
            const isValidate2 = this.$refs["innovation-gj-image"].checkData()
            if (!isValidate2) {
              return false;
            }
            this.applyLoading = true;
            this.$api.wcx.apply.innovationSubmit({
              ...this.formData,
              // innovationStatus: "2",
              sysAttMainVo: {
                sysAttMainIds: [].concat(this.formData.wcxVideo || [], this.formData.wcxOther || [])
              }
            }).then(response => {
              this.applyLoading = false;
              this.$message.success('提交成功');
              this.close();
            }).catch((e) => {
              this.applyLoading = false;
              this.$message.error(e.toString());
            });
          } else {
            const firstError = Object.values(validateResult)[0]?.[0]?.message;
            this.$message.error(firstError);
          }
        });
      }

    },
    close() {
      this.$tab.closeOpenPage({path: `/wcx/apply/innovation-my`});
    },
  }
}
</script>

<style lang="less" scoped>
.t-row {
  margin-bottom: 14px;
}

.step-card {
  height: 100%;
  margin-bottom: 14px;
}
</style>
